//
//  MineViewController.m
//  BabyAndBabyDriver
//
//  Created by 范琦 on 16/8/10.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "MineViewController.h"
#import "MineTableViewCell.h"
#import "MineHeaderView.h"
#import "ChangePhoneNumberViewController.h"
#import "ContactCustomerServiceViewController.h"
#import "AboutUsViewController.h"

@interface MineViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) MineHeaderView *MineHeaderView;
@property (nonatomic, strong) NSMutableArray *listArr;

@property (nonatomic, strong) NSString *head_img;
@property (nonatomic, strong) NSString *nickname;
@property (nonatomic, strong) NSNumber *month_jobs;
@property (nonatomic, strong) NSString *commission;
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _listArr = [NSMutableArray array];
    [self getData];
    [self creatTableView];
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)getData
{
    YTKNetHandle *api = [[YTKNetHandle alloc]initWithUrl:@"User/info.json" paramDic:@{@"token":TOKEN} RegisterApiMethod:RequestMethodPost];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSLog(@"%@", request.responseBody);
        NSDictionary *dic = request.responseBody[@"result"];
        _head_img = dic[@"head_img"];
        _nickname = dic[@"nickname"];
        _month_jobs = dic[@"month_jobs"];
        _commission = dic[@"commission"];
        
        [_MineHeaderView.AvatarImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@IMAGESMALL, _head_img]] placeholderImage:nil];
        _MineHeaderView.nameLabel.text = _nickname;
   
        //        NSLog(@"%@",dic);
    } failure:^(YTKBaseRequest *request) {
        
    }];
}

- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, _MineHeaderView.frame.size.height, KSCREENWIDTH, KSCREENHEIGHT  - _MineHeaderView.bounds.size.height - 64) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"MineTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:_tableView];
    _tableView.sectionFooterHeight = 0;
    
    self.MineHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"MineHeaderView" owner:nil options:nil] lastObject];
    _MineHeaderView.frame = CGRectMake(0, 0, KSCREENWIDTH, 180 * KSCREENHEIGHT / 667);
    //    [[_mainHeaderView.bigButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
    //        [self getDistrictData];
    //        [self creatPickerView:_recommendTop.bigButton];
    //    }];
    
    [self.view addSubview:_MineHeaderView];
    _tableView.tableHeaderView =_MineHeaderView;
    
}

#pragma mark - TableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if (indexPath.row == 0) {
        cell.titleLabel.text = @"更换手机";
    } else if (indexPath.row == 1) {
        cell.titleLabel.text = @"联系客服";
    } else if (indexPath.row == 2) {
        cell.titleLabel.text = @"关于我们";
    } else  {
        cell.titleLabel.text = @"退出账户";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        ChangePhoneNumberViewController *change = [[ChangePhoneNumberViewController alloc] init];
        [self.navigationController pushViewController:change animated:YES];
    } else if (indexPath.row == 1) {
        ContactCustomerServiceViewController *contact = [[ContactCustomerServiceViewController alloc] init];
        [self.navigationController pushViewController:contact animated:YES];
    } else if (indexPath.row == 2) {
        AboutUsViewController *contact = [[AboutUsViewController alloc] init];
        [self.navigationController pushViewController:contact animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
